#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int N = 1510;
char b[N][N];
int st[N][N];
int st1[2 * N][2 * N];
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
int f;
int n, m;
string s;
void bfs(int sx, int sy)
{
	queue<pii> q;
	q.push({ sx,sy });
	st[sx][sy] = 1;
	while (q.size())
	{
		if (f) break;
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int rx = x + dx[i];
			int ry = y + dy[i];
			if (rx <= 0) rx = 2 * n;
			if (ry <= 0) ry = 2 * m;
			if (rx > 2 * n) rx = 1;
			if (ry > 2 * m) ry = 1;

			int xx = (rx - 1) % n + 1;
			int yy = (ry - 1) % m + 1;
			if (b[xx][yy] == '#') continue;
			if (st1[rx][ry] == 1) continue;
			st1[rx][ry] == 1;
			if (rx <= m && ry <= n)
			{
				st[rx][ry] = 1;
			}
			else if (st[xx][yy] == 1)
			{
				f = 1;
				break;
			}
			q.push({ rx,ry });

		}
	}
}
int main()
{
	int x, y;
	while (cin >> n >> m)
	{
		f = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> s;
			for (int j = 1; j <= m; j++)
			{
				b[i][j] = s[j - 1];
				if (b[i][j] == 'S')
				{
					x = i;
					y = j;
				}
			}
		}
		bfs(x, y);
		//cout<<st[1][3]<<' '<<st1[6][3];
		if (f) cout << "Yes";
		else cout << "No";
		cout << endl;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				st[i][j] = 0;
				st1[i][j] = 0;
			}
		}
	}


	return 0;
}
